#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys, re, pipes, subprocess


mystem_process = subprocess.Popen("./mystem -c -l -e utf8", shell=True, stdin=sys.stdin, stdout=subprocess.PIPE)

for line in mystem_process.stdout:
  line = unicode(line, "utf8")

  line = re.sub(ur"\{([^\|^\}^\{^\?]+)\?*(\|[^\|^\}^\{\?]+\?*)*\}", ur"\1", line, re.U)
  print line


